/*
Copyright (c) 2010, Daniele Simonetti
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QModelIndex>

class PlayList;
class PlaylistEntry;

class QAction;
class QActionGroup;
class QContextMenuEvent;
class QMenu;
class QTimer;
class QCloseEvent;

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    PlayList* playList      ()                  const;
    void setWindowTitle     (const QString &)        ;

signals:
    void mouseMove          (QMouseEvent*);
    void mousePressed       (QMouseEvent*);
    void mouseReleased      (QMouseEvent*);    

    void streamPause        ();
    void streamPlay         (int, PlaylistEntry*);    
    void streamStop         ();

    void volumeChange       (int value);
    void positionChange     (int value);

protected:
    void changeEvent        (QEvent*e);
    void closeEvent         (QCloseEvent*e);
    void contextMenuEvent   (QContextMenuEvent*e);
    void mouseMoveEvent     (QMouseEvent*e);
    void mousePressEvent    (QMouseEvent*e);
    void mouseReleaseEvent  (QMouseEvent*e);
    void paintEvent         (QPaintEvent*e);

protected slots:
    void applyTheme     (QAction*);
    void playTriggered  ();
    void playTriggered  (QModelIndex);    
    void setPlayMode    (QAction*);
    void setSortOrder   (QAction*);
    void updateStatusBar();

public slots:    
    void addMusic       ();
    void addURI         ();
    void openPlaylist   ();
    void paused         ();
    void playing        ();
    void requestNext    ();
    void requestPrev    ();
    void savePlaylist   ();
    void savePlaylistAs ();
    void selectAll      ();
    void selectNone     ();
    void setStreamLen   (int value);
    void setStreamPos   (int value);
    void setVolume      (int value);
    void showAboutBox   ();
    void showTagEditor  (PlaylistEntry* entry);
    void showTagEditor  ();
    void stopped        ();
    void removeSelected ();
    void eraseSelected  ();
    void searchItem     (const QString& search);

private:
    Ui::MainWindow *ui;

    // Actions
    void cleanupActions(QMenu*);
    void initializeActions();

    // Models
    PlayList* _plModel;

    QAction* _aplay;
    QAction* _atag;
    QActionGroup* _agthemes;
    QActionGroup* _agsortOrder;
    QActionGroup* _agplaymode;

    QMenu*   _mctx;
    QMenu*   _msort;
    QMenu*   _mthemes;
    QMenu*   _mmode;
    QMenu*   _mvisual;
    QMenu*   _mpls;

    // Timer for status bar information
    QTimer* _timerSB;
};

#endif // MAINWINDOW_H
